<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<div class="aui-fullpage">
  <div class="aui-header-1">
    <h1>{{ 'system_adfs_label' | i18n }}</h1>
  </div>
  <div class="aui-block  aui-gutter-column-md">
    <div class="aui-header-2">
      <lv-group lvGutter="10px">
        <h2>{{ 'system_adfs_label' | i18n }}</h2>
        <lv-switch
          [(ngModel)]="adfsStatus"
          [lvControl]="true"
          (click)="switchChange()"
        ></lv-switch>
      </lv-group>
      <div pmpermission pmOperation="ModifyLdapConfig">
        <lv-group lvGutter="10px" *ngIf="editFlag">
          <span
            [ngClass]="{
              'aui-link': editForm.valid && isFileValid,
              'aui-link-disabled': !editForm.valid || !isFileValid
            }"
            (click)="test()"
          >
            {{ 'common_test_label' | i18n }}
          </span>
          <span
            [ngClass]="{
              'aui-link': editForm.valid && isFileValid && hasTest,
              'aui-link-disabled': !editForm.valid || !isFileValid || !hasTest
            }"
            (click)="save()"
          >
            {{ 'common_save_label' | i18n }}
          </span>
          <span class="aui-link" (click)="cancel()">
            {{ 'common_cancel_label' | i18n }}
          </span>
        </lv-group>
        <span
          *ngIf="!editFlag"
          [ngClass]="{
            'aui-link': adfsStatus,
            'aui-link-disabled': !adfsStatus
          }"
          (click)="modify()"
        >
          {{ 'common_modify_label' | i18n }}
        </span>
      </div>
    </div>
    <div class="dashed-line"></div>
    <ng-container *ngIf="adfsStatus; else closeTemplate">
      <div *ngIf="!editFlag">
        <lv-form>
          <lv-form-item *ngFor="let item of formItems">
            <lv-form-label>{{ item.label }}</lv-form-label>
            <lv-form-control>{{ item.content | nil }}</lv-form-control>
          </lv-form-item>
        </lv-form>
      </div>
      <div *ngIf="editFlag" class="edit-adfs-form">
        <lv-form [formGroup]="editForm">
          <lv-form-item>
            <lv-form-label>{{
              'system_adfs_select_provider_label' | i18n
            }}</lv-form-label>
            <lv-form-control>
              <lv-select
                lvDisabled
                [lvOptions]="providerOptions"
                formControlName="provider"
                lvValueKey="value"
                class="form-control-input"
              ></lv-select>
            </lv-form-control>
          </lv-form-item>
          <lv-form-item>
            <lv-form-label lvRequired>{{
              'common_name_label' | i18n
            }}</lv-form-label>
            <lv-form-control [lvErrorTip]="nameErrorTip">
              <input
                lv-input
                type="text"
                formControlName="name"
                class="form-control-input"
              />
            </lv-form-control>
          </lv-form-item>
          <lv-form-item>
            <lv-form-label lvRequired>
              {{ 'system_adfs_provider_url_label' | i18n }}
              <i
                lv-icon="aui-icon-help"
                lv-tooltip="{{ 'system_adfs_provider_url_tip_label' | i18n }}"
                lvTooltipTheme="light"
                lvTooltipPosition="right"
                class="configform-constraint"
                lvColorState="true"
              ></i>
            </lv-form-label>
            <lv-form-control [lvErrorTip]="proUrlErrorTip">
              <input
                lv-input
                type="text"
                formControlName="proUrl"
                class="form-control-input"
              />
            </lv-form-control>
          </lv-form-item>
          <lv-form-item>
            <lv-form-label>{{
              'system_adfs_callback_url_label' | i18n
            }}</lv-form-label>
            <lv-form-control>
              <input
                lv-input
                type="text"
                formControlName="calUrl"
                class="form-control-input"
              />
              <div class="callback-tips">
                <i lv-icon="lv-icon-status-info"></i>
                <p>{{ 'system_adfs_callback_url_tips_label' | i18n }}</p>
              </div>
            </lv-form-control>
          </lv-form-item>
          <lv-form-item>
            <lv-form-label lvRequired>{{
              'system_adfs_client_id_label' | i18n
            }}</lv-form-label>
            <lv-form-control [lvErrorTip]="clientIdErrorTip">
              <input
                lv-input
                type="text"
                formControlName="clientID"
                placeholder="{{ 'system_adfs_client_id_tips_label' | i18n }}"
                class="form-control-input"
              />
            </lv-form-control>
          </lv-form-item>
          <lv-form-item>
            <lv-form-label lvRequired>{{
              'system_adfs_client_password_label' | i18n
            }}</lv-form-label>
            <lv-form-control [lvErrorTip]="clientPasErrorTip">
              <div class="form-control-input">
                <aui-inupt-with-eye
                  formControlName="clientPas"
                  placeholder="{{
                    'system_adfs_client_password_tips_label' | i18n
                  }}"
                ></aui-inupt-with-eye>
              </div>
            </lv-form-control>
          </lv-form-item>
          <lv-form-item>
            <lv-form-label [lvRequired]="!hasConfig">{{
              'system_ca_certificate_label' | i18n
            }}</lv-form-label>
            <lv-form-control>
              <lv-upload
                lvAccept=".pem,.cer"
                lvShowUpload="false"
                [lvFilters]="filters"
                (lvFilesChange)="filesChange($event)"
                lvPlaceholder="{{
                  'protection_upload_placeholder_label' | i18n
                }}"
                class="form-control-input"
              ></lv-upload>
            </lv-form-control>
          </lv-form-item>
        </lv-form>
      </div>
    </ng-container>
    <ng-template #closeTemplate>
      <div class="closeStatus">
        <lv-empty
          lvDescription="{{ 'system_adfs_close_tip_label' | i18n }}"
        ></lv-empty>
      </div>
    </ng-template>
  </div>
</div>
